<template>
<!--入库单详情使用，不包含查询条件-->
  <a-card :bordered="false">
    <a-tabs>
      <a-tab-pane key="cg" tab="订单二维码">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24"> </a-row>
          </a-form>
        </div>
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->

        <!-- table区域-begin -->
        <div>
          <a-table
            ref="table"
            size="middle"
            :scroll="{ x: true }"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            class="j-table-force-nowrap1"
            @change="handleTableChange"
          >
            <template slot="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text, record">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
              <img
                v-else
                :src="getImgView(text)"
                :preview="record.id"
                height="25px"
                alt=""
                style="max-width: 80px; font-size: 12px; font-style: italic"
              />
            </template>
            <template slot="fileSlot" slot-scope="text">
              <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
              <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
                下载
              </a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <a @click="handleEdit(record)">编辑</a>

              <a-divider type="vertical" />
              <a-dropdown>
                <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a @click="handleDetail(record)">详情</a>
                  </a-menu-item>
                  <a-menu-item>
                    <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                      <a>删除</a>
                    </a-popconfirm>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </span>
          </a-table>
        </div>
      </a-tab-pane>
      <a-tab-pane key="ckDetail" tab="物料出入库明细">
        <buss-in-out-detail-list-form
          ref="realForm"
          :detailId="detailId"
          :code="code"
          :quantity="itemQuantity"
        ></buss-in-out-detail-list-form>
      </a-tab-pane>
      <a-tab-pane v-if="itemProcurementDetailId" key="cgOrder" tab="采购订单">
        <buss-material-procurement-list-form
          ref="BussMaterialProcurementList"
          :procurementDetailId="itemProcurementDetailId"
          :arrivalNum ="itemArrivalNum"
        ></buss-material-procurement-list-form>
      </a-tab-pane>
    </a-tabs>
    <tsl-wm-barcode-modal ref="modalForm" @ok="modalFormOk"></tsl-wm-barcode-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import TslWmBarcodeModal from './modules/TslWmBarcodeModal'
import { deleteAction, getAction, putAction, postAction } from '@api/manage'

import BussInOutDetailListForm from '@/components/base/modal/BussInOutDetailListForm'
import BussMaterialProcurementListForm from '@/views/business/barcode/modules/BussMaterialProcurementListForm'

import { param } from '../../../utils'

export default {
  name: 'TslWmBarcodeList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    TslWmBarcodeModal,
    BussInOutDetailListForm,
    BussMaterialProcurementListForm,
  },
  props: {
    //表单禁用
    barcode: {
      type: String,
      default: '',
      required: false,
    },
    category: {
      type: String,
    },
    modalWidth: {
      type: Number,
      required: false,
      default: 1250,
    },
    checkval: {
      type: String,
      default: 'radio',
    },
    supplierId: {
      type: String,
      required: false,
      default: '',
    },
    code: {
      type: String,
      default: '',
    },
    quantity: {
      type: String,
      default: '',
    },
    materialId: {
      type: String,
      default: '',
    },
    batch: {
      type: String,
      default: '',
    },
    procurementDetailId: {
      type: String,
      default: '',
    },
    arrivalNum: {
      type: Number,
      default: '',
    },
  },
  watch: {
    category(newValue) {
      // 当category变更时，可以进行一些处理
      console.log('Category changed to1:', newValue)
      this.queryParam = { id: newValue }
      this.detailId = newValue
    },
    code(newValue) {
      // 当category变更时，可以进行一些处理
      console.log('Category changed to2:', newValue)
      this.code = newValue
    },
    quantity(newValue) {
      // 当category变更时，可以进行一些处理
      console.log('Category changed to31:', newValue)
      this.itemQuantity = newValue
    },
    procurementDetailId(newValue) {
      // 当category变更时，可以进行一些处理
      console.log('Category changed to4:', newValue)
      this.itemProcurementDetailId = newValue
    },
    arrivalNum(newValue) {
      // 当category变更时，可以进行一些处理
      console.log('Category changed to4:', newValue)
      this.itemArrivalNum = newValue
    },
  },
  data() {
    return {
      description: '条形码总表管理页面',
      dataSource: [],
      detailId: '',
      itemQuantity:'',
      itemProcurementDetailId: '',
      itemArrivalNum:'',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '条形码',
          align: 'center',
          dataIndex: 'barcode',
        },
        {
          title: '物料名称',
          align: 'center',
          dataIndex: 'materialName',
        },
        {
          title: '物料规格',
          align: 'center',
          dataIndex: 'materialSpec',
        },
        {
          title: '物料批号',
          align: 'center',
          dataIndex: 'batchNo',
        },
        {
          title: '供应商批号',
          align: 'center',
          dataIndex: 'supplierBatchNo',
        },
        {
          title: '备用批号',
          align: 'center',
          dataIndex: 'batchNoReserve',
        },
        {
          title: '生产日期',
          align: 'center',
          dataIndex: 'produceDate',
        },
        {
          title: '生产商',
          align: 'center',
          dataIndex: 'manufacturer',
        },
        {
          title: '失效日期',
          align: 'center',
          dataIndex: 'expirationDate',
        },
        {
          title: '供应商',
          align: 'center',
          dataIndex: 'supplier',
        },
        {
          title: '主单位',
          align: 'center',
          dataIndex: 'meUnit_dictText',
        },
        {
          title: '辅单位',
          align: 'center',
          dataIndex: 'auUnit_dictText',
        },
        {
          title: '入库数量',
          align: 'center',
          dataIndex: 'meQuantity',
        },
        {
          title: '入库辅数量',
          align: 'center',
          dataIndex: 'auQuantity',
        },
        {
          title: '入库库位',
          align: 'center',
          dataIndex: 'instockLocator',
        },
        {
          title: '入库时间',
          align: 'center',
          dataIndex: 'instockDate',
        },
        {
          title: '质检时间',
          align: 'center',
          dataIndex: 'qualityCheckDate',
        },
        {
          title: '条形码状态',
          align: 'center',
          dataIndex: 'barcodeStatus_dictText',
        },
        {
          title: '入库类型',
          align: 'center',
          dataIndex: 'instockType_dictText',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/barcode/tslWmBarcode/list',
        delete: '/barcode/tslWmBarcode/delete',
        deleteBatch: '/barcode/tslWmBarcode/deleteBatch',
        exportXlsUrl: '/barcode/tslWmBarcode/exportXls',
        importExcelUrl: 'barcode/tslWmBarcode/importExcel',

        getByCondition: '/detail/bussInventoryDetails/getByCondition',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {},
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'barcode', text: '条形码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'materialId', text: '物料编码', dictCode: '' })
      fieldList.push({ type: 'string', value: 'materialName', text: '物料名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'materialSpec', text: '物料规格', dictCode: '' })
      fieldList.push({ type: 'string', value: 'batchNo', text: '物料批号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'supplierBatchNo', text: '供应商批号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'batchNoReserve', text: '备用批号', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'produceDate', text: '生产日期' })
      fieldList.push({ type: 'string', value: 'manufacturer', text: '生产商', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'expirationDate', text: '失效日期' })
      fieldList.push({ type: 'string', value: 'supplier', text: '供应商', dictCode: '' })
      fieldList.push({ type: 'string', value: 'meUnit', text: '主单位', dictCode: '' })
      fieldList.push({ type: 'string', value: 'auUnit', text: '辅单位', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'meQuantity', text: '入库数量', dictCode: '' })
      fieldList.push({ type: 'BigDecimal', value: 'auQuantity', text: '入库辅数量', dictCode: '' })
      fieldList.push({ type: 'string', value: 'instockBillNo', text: '入库单号', dictCode: '' })
      fieldList.push({ type: 'string', value: 'instockDetailId', text: '入库明细ID', dictCode: '' })
      fieldList.push({ type: 'string', value: 'instockLocator', text: '入库库位', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'instockDate', text: '入库时间' })
      fieldList.push({ type: 'datetime', value: 'qualityCheckDate', text: '质检时间' })
      fieldList.push({
        type: 'string',
        value: 'barcodeStatus',
        text: '条形码状态(1:新建，2：待检验，3：合格，4：让步放行，5：不合格)',
        dictCode: '',
      })
      fieldList.push({ type: 'string', value: 'instockType', text: '入库类型', dictCode: '' })
      this.superFieldList = fieldList
    },

    loadData() {
      //获取二维码数据请求

      if (this.barcode != null) {
        console.log('传入barcode' + this.barcode)
        let param = { barcode: this.barcode }
        getAction(this.url.list, param).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
          }
        })
      }

      //获取出入库明细请求
      let detailParam = { code: this.code, materialId: this.materialId, batch: this.batch }
      console.log('-----------------------')
      console.log(this.code)
      console.log(this.materialId)
      console.log(this.batch)
      console.log(this.itemProcurementDetailId)
      console.log(this.itemArrivalNum)

      getAction(this.url.getByCondition, detailParam).then((res) => {
        console.log(this.batch)
        if (res.success) {
          //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          this.detailId = res.result.id
          this.itemQuantity = res.result.quantity
        }
      })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>